#ifndef _FEATURETERM_KNOWLEDGE_BASE
#define _FEATURETERM_KNOWLEDGE_BASE


class KBSortIndex {
public:

	Sort *s;
	List<FeatureTerm> fterms;
};


class KBNameIndex {
public:

	Symbol *name;
	List<FeatureTerm> fterms;
};



class FTKBase {
public:
	FTKBase(Ontology *o);
	FTKBase(FILE *fp,Ontology *o);
	~FTKBase();

	void Delete();

	void create_boolean_objects(Ontology *o);

	void AddFT(FeatureTerm *f);
	void AddUndefinedFT(FeatureTerm *f);
	void DeleteFT(FeatureTerm *f);

	List<FeatureTerm> *SearchFT(Symbol *name);
	FeatureTerm *SearchUndefinedFT(Symbol *name);	// Searches whether an undefined term with this name exists
	List<FeatureTerm> *SearchFT(Sort *s);
	List<FeatureTerm> *RetrieveFT(FeatureTerm *pattern);

	// These functions do not search in the used memories:
	List<FeatureTerm> *LocalSearchFT(Symbol *name);
	List<FeatureTerm> *LocalSearchFT(Sort *s);
	List<FeatureTerm> *LocalRetrieveFT(FeatureTerm *pattern);

	bool MemberP(FeatureTerm *f);
	bool MemberP(FeatureTermContainer *ft);

	bool ImportNOOS(FILE *fp,Ontology *o);
	bool ImportNOOS(char *filename,Ontology *o);

	bool save(FILE *fp,FTKBase *domain_model);
	bool load(FILE *fp,Ontology *o);

	int get_n_undefined_terms(void);
	void print_undefined_terms(void);

	int get_n_terms(void);

	void uses(FTKBase *base);

private:
	KBNameIndex *SearchName(Symbol *name);
	KBSortIndex *SearchSort(Sort *sort);

	List<FeatureTerm> index;
	List<KBNameIndex> name_index;
	List<KBSortIndex> sort_index;

	List<FeatureTerm> undefined_terms;

	List<FTKBase> used_bases;
};

#endif
